/************************************************************
 * Project Name         [Thinking_In_Java]
 * File Name            [FileMenuToolBar.java]
 * Creation Date        [11-Jul-2014]
 * 
 * Copyright© ge.y.yang@gmail.com All Rights Reserved
 * 
 * Work hard, play harder, think big and keep fit
 ************************************************************/
package pkg_02_gui.notepad_V1.ui.file;

import java.awt.FlowLayout;
import java.awt.event.ActionListener;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JToolBar;

/**
 * 浮动文件工具栏
 * 
 * @author 不落的太阳(Sean Yang)
 * @version 1.0
 * @since JDK 6
 * 
 */
public class FileMenuToolBar extends JToolBar {

	private static final long serialVersionUID = -2064363860216439209L;

	private ActionListener listener = null; // 文件菜单监听器

	private Icon newIcon = null;
	private Icon openIcon = null;
	private Icon saveIcon = null;

	private JButton newButton = null;
	private JButton openButton = null;
	private JButton saveButton = null;

	/**
	 * 初始化文件浮动工具栏
	 */
	private void init() {
		newIcon = new ImageIcon(
				"src_03_best_practices/pkg_02_gui//notepad_V1/icons/new.gif");
		openIcon = new ImageIcon(
				"src_03_best_practices/pkg_02_gui//notepad_V1/icons/open.gif");
		saveIcon = new ImageIcon(
				"src_03_best_practices/pkg_02_gui//notepad_V1/icons/save.gif");

		newButton = new JButton(newIcon); // 新建文件
		openButton = new JButton(openIcon); // 打开文件
		saveButton = new JButton(saveIcon); // 保存文件

		newButton.addActionListener(listener);
		openButton.addActionListener(listener);
		saveButton.addActionListener(listener);

		newButton.setToolTipText("新建文件");
		openButton.setToolTipText("打开文件");
		saveButton.setToolTipText("保存文件");

		this.add(newButton);
		this.add(openButton);
		this.add(saveButton);

		/**
		 * 初始化浮动工具栏
		 */
		setFloatable(true); // 设置工具栏为可浮动
		FlowLayout flowLayout = new FlowLayout(FlowLayout.LEADING, 0, 0);
		setLayout(flowLayout);
		flowLayout.setAlignOnBaseline(true);

	}

	public FileMenuToolBar(ActionListener listener) {
		this.listener = listener;
		init();
	}

	public JButton getNewButton() {
		return newButton;
	}

	public JButton getOpenButton() {
		return openButton;
	}

	public JButton getSaveButton() {
		return saveButton;
	}
}
